home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Inside Mac Games Volume 5 #3
/
IMG 46 Vol 5-3.iso
/
More Goodies
/
More For Your Game
/
Realmz
/
Character Master Source
/
Nemesis Framework
/
Sources
/
nemesis dialogs.cpp
< prev
next >
Wrap
Text File
|
1996-07-03
|
25KB
|
1,037 lines
//••••••••••••••••••••••••••••••••••••
// Some dialog utilities
//••••••••••••••••••••••••••••••••••••
//••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
// Some required externals
extern void HandleEventHook( EventRecord * );
extern void AlertUpdateMenusHook();
extern nemesisGlobalPtr G;
//•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
#pragma mark ••••• Dialog Items •••••
Handle NemesisGetDialogItemHandle( DialogRef theDialog, int itemNumber )
{
Rect tempRect;
short tempItemType = -1;
Handle tempHandle;
GetDialogItem( theDialog, itemNumber, &tempItemType, &tempHandle, &tempRect );
if( tempItemType < 0 ) // assume the call failed
tempHandle = nil;
return tempHandle;
}
short NemesisGetDialogItemType( DialogRef theDialog, int itemNumber )
{
Rect tempRect;
short tempItemType = -1;
Handle tempHandle;
GetDialogItem( theDialog, itemNumber, &tempItemType, &tempHandle, &tempRect );
return tempItemType;
}
void NemesisGetDialogItemRect( DialogRef theDialog, int theItem, Rect &theRect )
{
short itemType = -1;
Handle itemHandle;
GetDialogItem(theDialog, theItem, &itemType, &itemHandle, &theRect);
if(itemType < 0)
SetRect( &theRect, 0, 0, 0, 0 );
}
Boolean NemesisFlashItem (DialogRef theDialog, EventRecord *theEvent, short itemHit)
{
Boolean result = false; // assume it wasn't a button
Rect itemRect;
Handle itemHandle;
Point mousePt;
long temp;
if ( NemesisGetDialogItemType( theDialog, itemHit ) != kButtonDialogItem)
{
return result; // not a button
}
// if item 1 is a button, assume it is the OK button and assume item 2 is cancel
itemHandle = NemesisGetDialogItemHandle(theDialog, itemHit);
if( itemHandle == nil ) return result; // Check for nil handle
// set event->where to button coordinates
NemesisGetDialogItemRect( theDialog, itemHit, itemRect );
mousePt.h = itemRect.left + 1;
mousePt.v = itemRect.top + 1;
NemesisLocalToGlobal (theDialog, mousePt, &mousePt);
theEvent->where = mousePt; // event->where always global
// flash the button
HiliteControl( (ControlHandle)itemHandle, 1 );
Delay( 8, &temp );
HiliteControl( (ControlHandle)itemHandle, 0 );
// make it a mousedown event
theEvent->what = 1;
result = true;
return result;
}
#pragma mark ••••• Text Edit Items •••••
void NemesisNumToItemText( DialogRef theDialog, int theItem, long theNumber )
{
Str255 tempStr;
NumToString( theNumber, tempStr );
NemesisSetItemText( theDialog, theItem, tempStr );
}
void NemesisSetItemText( DialogRef theDialog, int theItem, Str255 theString )
{
Handle theItemHandle;
Str255 tempStr;
if( NemesisGetDialogItemType( theDialog, theItem ) == kEditTextDialogItem )
{
NemesisGetItemText( theDialog, theItem, tempStr );
if( !EqualString( tempStr, theString, true, true ) )
{
theItemHandle = NemesisGetDialogItemHandle( theDialog, theItem );
SetDialogItemText( theItemHandle, theString );
}
}
}
long NemesisItemTextToNum( DialogRef theDialog, int theItem )
{
Str255 tempStr;
long theNumber;
int count;
int startCount = 0;
Boolean valid = true;
NemesisGetItemText( theDialog, theItem, tempStr );
if( tempStr[0] == 0 ) return 0;
if( tempStr[0] > 9 )
{
if( tempStr[1] == 45 ) // First char is -
{
if( tempStr[0] > 11 ) // First check: number to long
{
valid = false;
}
else if( ((tempStr[0] >10) && (tempStr[2] > '2')) ||
((tempStr[0] >10) && (tempStr[3] > '0')) ||
((tempStr[0] >10) && (tempStr[4] > '0')) ||
((tempStr[0] >10) && (tempStr[5] > '0')) ||
((tempStr[0] >10) && (tempStr[6] > '0')) ||
((tempStr[0] >10) && (tempStr[7] > '0')) ||
((tempStr[0] >10) && (tempStr[8] > '0')) ||
((tempStr[0] >10) && (tempStr[9] > '0')) ||
((tempStr[0] >10) && (tempStr[10] > '0')) ||
((tempStr[0] >10) && (tempStr[11] > '0')) )
{
valid = false;
}
}
else
{
if( tempStr[0] > 10 ) // First check: number to long
{
valid = false;
}
else if( ((tempStr[0] >10) && (tempStr[1] > '2')) ||
((tempStr[0] >10) && (tempStr[2] > '0')) ||
((tempStr[0] >10) && (tempStr[3] > '0')) ||
((tempStr[0] >10) && (tempStr[4] > '0')) ||
((tempStr[0] >10) && (tempStr[5] > '0')) ||
((tempStr[0] >10) && (tempStr[6] > '0')) ||
((tempStr[0] >10) && (tempStr[7] > '0')) ||
((tempStr[0] >10) && (tempStr[8] > '0')) ||
((tempStr[0] >10) && (tempStr[9] > '0')) ||
((tempStr[0] >10) && (tempStr[10] > '0')) )
{
valid = false;
}
}
}
// Now to check for letters in the number
if( valid )
{
if( tempStr[1] == 45 ) // First char is -
startCount = 2;
else
startCount = 1;
for( count = startCount; count <= tempStr[0]; count++ )
{
if( (tempStr[count] < 48) || (tempStr[count] > 57) )
valid = false;
}
}
if( valid )
StringToNum( tempStr, &theNumber );
else
theNumber = -2000000001; // One smaller than the min I'm setting
return theNumber;
}
void NemesisGetItemText( DialogRef theDialog, int theItem, Str255 theString )
{
Handle theItemHandle;
theString[0] = 0; // Assume failure
if( NemesisGetDialogItemType( theDialog, theItem ) == kEditTextDialogItem )
{
theItemHandle = NemesisGetDialogItemHandle( theDialog, theItem );
GetDialogItemText( theItemHandle, theString );
}
}
void NemesisSelectItemText( DialogRef theDialog, int theItemNumber )
{
if( NemesisGetDialogItemType( theDialog, theItemNumber ) == kEditTextDialogItem )
SelectDialogItemText( theDialog, theItemNumber, 0, 32767 );
}
#pragma mark ••••• Dialog Fonts •••••
void NemesisSetFont( WindowRef theWindow, Str255 fName, int fSize, int fStyle )
{
short fNum;
GrafPtr oldPort;
// Save the current port
GetPort( &oldPort );
SetPort( theWindow );
GetFNum( fName, &fNum );
TextFont( fNum );
TextFace( fStyle );
TextSize( fSize );
TextMode( patCopy );
// Restore original port
SetPort( oldPort );
}
void NemesisSetFont( WindowRef theWindow, int fNum, int fSize, int fStyle )
{
GrafPtr oldPort;
// Save the current port
GetPort( &oldPort );
SetPort( theWindow );
TextFont( fNum );
TextFace( fStyle );
TextSize( fSize );
TextMode( patCopy );
// Restore original port
SetPort( oldPort );
}
#pragma mark ••••• Dialog Strings •••••
void NemesisDrawString( WindowRef theWindow, int x, int y, Str255 theString )
{
Point oldPosition;
GrafPtr oldPort;
// Save the current port
GetPort( &oldPort );
SetPort( theWindow );
GetPen( &oldPosition );
MoveTo( x, y );
DrawString( theString );
MoveTo( oldPosition.h, oldPosition.v );
// Restore original port
SetPort( oldPort );
}
#pragma mark ••••• Dialog Controls ••••••••
Boolean NemesisIsItemAControl( DialogRef theDialog, int theItem )
{
int itemType = NemesisGetDialogItemType( theDialog, theItem );
Boolean isControl = false;
if( itemType == kControlDialogItem )
isControl = true;
else
{
switch( itemType )
{
case kButtonDialogItem:
case kCheckBoxDialogItem:
case kRadioButtonDialogItem:
case kResourceControlDialogItem: isControl = true; break;
default : isControl = false; break;
}
}
return isControl;
}
void NemesisSetControlTitle( DialogRef theDialog, int theItem, const Str255 theTitle )
{
Handle theItemHandle;
Str255 tempStr;
if( NemesisIsItemAControl( theDialog, theItem ) )
{
NemesisGetControlTitle( theDialog, theItem, tempStr );
theItemHandle = NemesisGetDialogItemHandle( theDialog, theItem );
if( theItemHandle )
{
if( !EqualString( tempStr, theTitle, true, true ) )
SetControlTitle( (ControlRef)theItemHandle, theTitle );
}
}
}
void NemesisGetControlTitle( DialogRef theDialog, int theItem, Str255 theTitle )
{
Handle theItemHandle;
theTitle[0] = 0; // Nullify it in case of failure
if( NemesisIsItemAControl( theDialog, theItem ) )
{
theItemHandle = NemesisGetDialogItemHandle( theDialog, theItem );
if( theItemHandle )
GetControlTitle( (ControlRef)theItemHandle, theTitle );
}
}
int NemesisGetControlValue( DialogRef theDialog, int theItem )
{
Handle theItemHandle;
int temp = 0;
if( NemesisIsItemAControl( theDialog, theItem ) )
{
theItemHandle = NemesisGetDialogItemHandle( theDialog, theItem );
if( theItemHandle )
temp = GetControlValue( (ControlRef)theItemHandle );
}
return temp;
}
void NemesisSetControlValue( DialogRef theDialog, int theItem, int theValue )
{
Handle theItemHandle;
if( NemesisIsItemAControl( theDialog, theItem ) )
{
theItemHandle = NemesisGetDialogItemHandle( theDialog, theItem );
if( theItemHandle )
SetControlValue( (ControlRef)theItemHandle, theValue );
}
}
void NemesisDimControl( DialogRef theDialog, int theItem )
{
Handle theControl;
if( NemesisIsItemAControl( theDialog, theItem ) )
{
theControl = NemesisGetDialogItemHandle( theDialog, theItem );
if( theControl )
HiliteControl( (ControlRef)theControl, 255 );
}
}
void NemesisUndimControl( DialogRef theDialog, int theItem )
{
Handle theControl;
if( NemesisIsItemAControl( theDialog, theItem ) )
{
theControl = NemesisGetDialogItemHandle( theDialog, theItem );
if( theControl )
HiliteControl( (ControlRef)theControl, 0 );
}
}
#pragma mark ••••• Dialog filters and user items •••••
pascal Boolean NemesisModalFilter( DialogRef theDialog, EventRecord * theEvent, short *itemHit)
{
Boolean callNormalHandler = false; /* call our event handler? */
Boolean result = false; /* to return to ModalDialog */
char theKey;
WindowRef hitWindow;
short windowPart;
windowPart = FindWindow(theEvent->where, &hitWindow);
switch(theEvent->what)
{
// We update/activate app windows, ModalDialog() does dialog window.
case updateEvt:
case activateEvt:
if ( IsNemesisWindow( (WindowRef)theEvent->message) ) // an app window?
{
callNormalHandler = true;
}
break;
/* Allow command dragging a window other than the dialog. This is
really cool, because it allows you to move a hidden window
out from behind a modal dialog so you can see what's going on.
All other mouse clicks go to ModalDialog(). */
case mouseDown:
if ( theEvent->modifiers & cmdKey )
{
if (windowPart == inDrag && (hitWindow != theDialog))
{
callNormalHandler = true;
}
}
break;
/* All keystrokes go to ModalDialog(). Except we want to detect
command period keystroke for cancel, and return/enter key to
hit the default button. */
case keyDown:
case autoKey:
theKey = (char)(theEvent->message & charCodeMask); // get the key pressed
if (theEvent->modifiers & cmdKey) // command key down
{
if(theKey == '.') // if it's the period
{
result = NemesisFlashItem(theDialog, theEvent, cancel);
*itemHit = cancel;
}
}
else // no command key
{
if (theKey == 0x0D || theKey == 0x03) // return or enter
{
result = NemesisFlashItem(theDialog, theEvent, ok);
*itemHit = ok;
}
else if (theKey == 0x1B) // escape key
{
result = NemesisFlashItem(theDialog, theEvent, cancel);
*itemHit = cancel;
}
}
break;
// Handle whatever other events are coming in such as
// null events, AppleEvents, etc.
default:
callNormalHandler = true;
break;
}
// if we're going to take care of it, call the normal handler
if (callNormalHandler)
{
HandleEventHook( theEvent );
}
return result;
}
void NemesisSetupDefaultButton( DialogRef theDialog, short defaultItem)
{
short itemType;
Rect itemRect;
Handle itemHandle;
GetDialogItem(theDialog, defaultItem, &itemType, &itemHandle, &itemRect);
// a little error control here
itemType &= ~kItemDisableBit; // don't care it it's enabled or not
if (itemType != kUserDialogItem)
return;
else
SetDialogItem( theDialog,
defaultItem,
itemType,
(Handle) G->DrawDefaultButtonUPP(),
&itemRect );
}
pascal void NemesisDrawDefaultButton( DialogRef theDialog, short item )
{
OSErr error = noErr;
short itemType = NemesisGetDialogItemType( theDialog, item );
Rect itemRect;
NemesisGetDialogItemRect( theDialog, item, itemRect );
PenState oldPen;
RGBColor oldForeColour;
Boolean inBack = false;
// just to be safe, let's make sure it's a button
if ( itemType != kButtonDialogItem )
return;
// save current pen
GetPenState(&oldPen);
// set it to what we want
PenNormal();
PenSize(3,3);
// dialog could be modeless. If in the background, set pen to grey
if ( theDialog != FrontWindow() || !G->SwitchedIn() )
{
inBack = true;
NemesisSetDimmedColour( itemRect, oldForeColour );
}
// outline it
InsetRect( &itemRect, -4, -4 );
FrameRoundRect( &itemRect, 16, 16 );
// restore original pen
if ( inBack )
NemesisRestoreDimmedColour( oldForeColour );
SetPenState( &oldPen );
}
void NemesisSetupOutline( DialogRef theDialog, short outlineItem)
{
short itemType = NemesisGetDialogItemType( theDialog, outlineItem );
Rect itemRect;
NemesisGetDialogItemRect( theDialog, outlineItem, itemRect );
// a little error control here
itemType &= ~kItemDisableBit; // don't care it it's enabled or not
if (itemType != kUserDialogItem)
return;
else
SetDialogItem( theDialog,
outlineItem,
itemType,
(Handle) G->DrawOutlineUPP(),
&itemRect);
}
pascal void NemesisDrawOutline( DialogRef theDialog, short item )
{
OSErr error = noErr;
Rect itemRect;
PenState oldPen;
RGBColor oldForeColour;
Boolean didGrey;
// Get the items Rect
NemesisGetDialogItemRect( theDialog, item, itemRect);
// Save the current state
GetPenState( &oldPen );
// set it to what we want
PenNormal();
didGrey = NemesisSetDimmedColour( itemRect, oldForeColour );
if( !didGrey )
PenPat( &qd.black );
// Make the outline a bit bigger than the item
InsetRect( &itemRect, -3, -3 );
FrameRect( &itemRect );
// restore original pen
if( didGrey )
NemesisRestoreDimmedColour( oldForeColour );
SetPenState( &oldPen );
}
#pragma mark ••••• Checkboxes and Radio buttons •••••
Boolean NemesisCheckItemsAreRadios( DialogRef theDialog, int firstButton, int lastButton )
{
int count;
Boolean theyAreRadios = true;
for( count = firstButton; count <= lastButton; count++ )
{
if( NemesisGetDialogItemType( theDialog, count ) != kRadioButtonDialogItem )
{
theyAreRadios = false;
break;
}
}
return theyAreRadios;
}
void NemesisSetActiveRadioButton( DialogRef theDialog, int firstButton, int lastButton, int theButton )
{
int count;
if( NemesisCheckItemsAreRadios( theDialog, firstButton, lastButton ) )
{
// First make sure all the buttons are off
for( count = firstButton; count <= lastButton; count++ )
{
if( NemesisGetControlValue( theDialog, count ) != kControlRadioButtonUncheckedValue )
NemesisSetControlValue( theDialog, count, kControlRadioButtonUncheckedValue );
}
// Now turn on the button we want
NemesisSetControlValue( theDialog, theButton, kControlRadioButtonCheckedValue );
}
}
int NemesisGetActiveRadioButton( DialogRef theDialog, int firstButton, int lastButton )
{
int count;
int tempValue;
count = (firstButton-1);
if( NemesisCheckItemsAreRadios( theDialog, firstButton, lastButton ) )
{
do
{
++count;
tempValue = NemesisGetControlValue( theDialog, count );
} while( (tempValue != kControlRadioButtonCheckedValue) && ( count <= lastButton ) );
}
else
count = -1;
return count;
}
void NemesisToggleCheckbox( DialogRef theDialog, int theBox )
{
if( NemesisGetDialogItemType( theDialog, theBox ) == kCheckBoxDialogItem )
{
if( NemesisGetControlValue( theDialog, theBox ) == kControlCheckboxCheckedValue )
NemesisUncheckCheckbox( theDialog, theBox );
else
NemesisCheckCheckbox( theDialog, theBox );
}
}
void NemesisSetCheckbox( DialogRef theDialog, int theBox, int theValue )
{
if( NemesisGetDialogItemType( theDialog, theBox ) == kCheckBoxDialogItem )
{
if( NemesisGetCheckboxValue( theDialog, theBox ) != theValue )
NemesisSetControlValue( theDialog, theBox, theValue );
}
}
void NemesisCheckCheckbox( DialogRef theDialog, int theBox )
{
if( NemesisGetDialogItemType( theDialog, theBox ) == kCheckBoxDialogItem )
{
if( NemesisGetCheckboxValue( theDialog, theBox ) != kControlCheckboxCheckedValue )
NemesisSetControlValue( theDialog, theBox, kControlCheckboxCheckedValue );
}
}
void NemesisUncheckCheckbox( DialogRef theDialog, int theBox )
{
if( NemesisGetDialogItemType( theDialog, theBox ) == kCheckBoxDialogItem )
{
if( NemesisGetCheckboxValue( theDialog, theBox ) != kControlCheckboxUncheckedValue )
NemesisSetControlValue( theDialog, theBox, kControlCheckboxUncheckedValue );
}
}
int NemesisGetCheckboxValue( DialogRef theDialog, int theBox )
{
int temp = -1;
if( NemesisGetDialogItemType( theDialog, theBox ) == kCheckBoxDialogItem )
{
temp = NemesisGetControlValue( theDialog, theBox );
}
return temp;
}
#pragma mark ••••• Nemesis Alert Dialogs ••••
void alertDialog::DoUpdateMenus()
{
AlertUpdateMenusHook();
}
OSErr NemesisGetAlert( int dialogID, Str255 theText )
{
OSErr error = noErr;
DialogRef theDialog;
error = NemesisGetDialog( dialogID, nil, kInFront, theDialog );
if( error ) return error;
NemesisSetupDefaultButton( theDialog, iAlertDefault );
// Stuff a pointer to the dialog in the WinRefCon
SetWRefCon( (WindowRef)theDialog,
(long)(new alertDialog(theDialog, nil)) );
NemesisSetDialogKind( theDialog, kAlertDKind );
// set the text in the dialog
ParamText( theText, "\p", "\p", "\p" );
NemesisShowDialog( theDialog );
// beep to alert the user
SysBeep( 30 );
return error;
}
OSErr NemesisStopAlert( Str255 theString )
{
OSErr error = noErr;
error = NemesisGetAlert( kStopID, theString );
return error;
}
OSErr NemesisCautionAlert( Str255 theString )
{
OSErr error = noErr;
error = NemesisGetAlert( kCautionID, theString );
return error;
}
OSErr NemesisNoteAlert( Str255 theString )
{
OSErr error = noErr;
error = NemesisGetAlert( kNoteID, theString );
return error;
}
OSErr NemesisStopAlert( int theIndID, int theStringNum )
{
OSErr error = noErr;
Str255 theString;
// get the message string
NemesisGetIndString ( theIndID, theStringNum, theString );
error = NemesisStopAlert( theString );
return error;
}
OSErr NemesisCautionAlert( int theIndID, int theStringNum )
{
OSErr error = noErr;
Str255 theString;
// get the message string
NemesisGetIndString ( theIndID, theStringNum, theString );
error = NemesisCautionAlert( theString );
return error;
}
OSErr NemesisNoteAlert( int theIndID, int theStringNum )
{
OSErr error = noErr;
Str255 theString;
// get the message string
NemesisGetIndString ( theIndID, theStringNum, theString );
error = NemesisNoteAlert( theString );
return error;
}
#pragma mark ••••• About Dialog •••••
void aboutDialogClass::DoFilterEvent( EventRecord *theEvent )
{
// Update the animation
if( !simpleAbout ) theCredits->DoAnimation();
// Call the base class for the rest of the stuff
baseDialog::DoFilterEvent( theEvent );
};
void aboutDialogClass::DoUpdateMenus()
{
AlertUpdateMenusHook();
};
void aboutDialogClass::DoItemHit( EventRecord *theEvent, int itemHit )
{
switch( itemHit )
{
case ok : NemesisPlayGoodClick(); // Play click sound
if( !simpleAbout )
delete theCredits;
else
DisposeDialog( thisDialog );
NemesisUpdateMenus( FrontWindow() );
break;
default : NemesisPlayBadClick();
break;
}
};
OSErr NemesisAboutBox( int theDialogID, int theDefaultButton, int theScrollItem )
{
CGrafPtr theDialog;
OSErr error = noErr;
error = NemesisGetDialog( theDialogID, nil, kInFront, ((DialogRef)(theDialog)) );
if( error ) return error;
NemesisSetupDefaultButton( (DialogRef)theDialog, theDefaultButton );
// Stuff a pointer to the dialog in the WinRefCon
SetWRefCon( (WindowRef)theDialog,
(long)(new aboutDialogClass((DialogRef)theDialog, nil)) );
NemesisSetDialogKind( ((DialogRef)theDialog), kAboutScrollDKind );
if( !NemesisControlKeyDown() )
{
// Setup the credits
((aboutDialogClass *)(NemesisGetBaseDPtr( (DialogRef)theDialog )))->SetCredits( new creditsScroll(theScrollItem, theDialog) );
// Check to see if there was an error during construction
error = ( (aboutDialogClass *)(NemesisGetBaseDPtr( (DialogRef)theDialog )) )->InitError();
if( error )
{
// So we only notify the user once.
if( G->HadFancyAboutMemError() )
{
switch(error)
{
case memFullErr:
case cTempMemErr:
case cNoMemErr: error = noErr;
break;
}
}
else
{
G->SetHadFancyAboutMemError();
switch(error)
{
case memFullErr:
case cTempMemErr:
case cNoMemErr: error = kNotEnoughMemForFancyAbout;
break;
}
}
((aboutDialogClass *)(NemesisGetBaseDPtr( (DialogRef)theDialog )))->MakeItSimple();
}
else
{
ShortenDITL( (DialogRef)theDialog, 1 ); // Get rid of last picture
}
}
else
{
((aboutDialogClass *)(NemesisGetBaseDPtr( (DialogRef)theDialog )))->MakeItSimple();
}
NemesisShowDialog( ((DialogRef)theDialog) );
return error;
}
#pragma mark ••••• Linked list maintanence •••••
void NemesisAddDialogToList( DialogRef theDialog )
{
if( !theDialog )
return; // Check we were not slipped a nil
DialogRef thisDialog;
baseModelessDialogPtr oldLastDialog;
if ( !G->DialogList() ) // This is the first dialog
{
G->SetDialogList( theDialog ); // Set the dialog list to point to the first dialog
// These next variable _should_ have been initialised correctly
// but I'm setting them here again, just in case
(NemesisGetBaseMlessPtr( theDialog ))->SetNextDialog( nil );
(NemesisGetBaseMlessPtr( theDialog ))->SetPrevDialog( nil );
}
else // Find old last dialog and introduce it to the new dialog
{
// Start at the beginning of the list and walk through it till
// we get to the old last dialog.
thisDialog = G->DialogList();
while( thisDialog )
{
oldLastDialog = NemesisGetBaseMlessPtr( thisDialog );
thisDialog = oldLastDialog->NextDialog();
}
// Plop the new dialog after the old last dialog
oldLastDialog->SetNextDialog( theDialog );
// Tell the new dialog about its ancestors( the old last dialog )
(NemesisGetBaseMlessPtr( theDialog ))->SetPrevDialog( oldLastDialog->ThisDialog() );
}
}
void NemesisRemoveDialogFromList ( DialogRef theDialog )
{
DialogRef previousDialog;
DialogRef nextDialog;
baseModelessDialogPtr theMlessDialog = NemesisGetBaseMlessPtr( theDialog );
// get previous and next dialogs, either could be nil values
previousDialog = theMlessDialog->PrevDialog();
nextDialog = theMlessDialog->NextDialog();
if( previousDialog ) // There is a dialog before this one
{
// Tell it about its promotion and who the new boss is
// (well ok, point it to the new next dialog)
(NemesisGetBaseMlessPtr( previousDialog ))->SetNextDialog( nextDialog );
if ( nextDialog )
{
// Tell the next dialog its underling has been sacked and
// show it the new junior.
// (well, set the next dialog to the previous dialog, cutting out the
// middle man so to speak…)
(NemesisGetBaseMlessPtr( nextDialog ))->SetPrevDialog( previousDialog );
}
}
else // There is no dialog before the one we are closing
{
// Put the next dialog at the bottom of the pile
G->SetDialogList( nextDialog );
if ( nextDialog ) // Current next dialog is now the first dialog
{
// Get rid of the prevDialog since there isn't one
(NemesisGetBaseMlessPtr( nextDialog ))->SetPrevDialog( (DialogRef)nil );
}
}
}
OSErr NemesisCloseAllDialogs()
{
OSErr error = noErr;
DialogRef theDialog = (DialogRef)FrontWindow();
baseModelessDialogPtr myDialog;
while ( theDialog )
{
myDialog = NemesisGetBaseMlessPtr( theDialog );
// Make sure we got a baseModelessDialogPtr from it
if( myDialog )
{
// close this dialog, if cancelled, return error
error = myDialog->DoClose();
if (error)
{
return error;
}
}
// Get the next dialog
theDialog = (DialogRef)GetNextWindow( (WindowRef)theDialog );
}
return error;
}
OSErr NemesisCloseThisDialog( DialogRef theDialog )
{
OSErr error = noErr;
baseModelessDialogPtr myDialog;
myDialog = NemesisGetBaseMlessPtr( theDialog );
// Make sure we got a baseModelessDialogPtr from it
if( myDialog )
{
// close this dialog, if cancelled, return error
error = myDialog->DoClose();
}
return error;
}
#pragma mark ••••• Misc Dialog Utilities •••••
void NemesisPlayGoodClick()
{
SHPlayByID( sClick, nil );
}
void NemesisPlayBadClick()
{
SHPlayByID( sBadClick, nil );
}
void NemesisSetDialogKind( DialogRef &theDialog, int theKind )
{
(NemesisGetBaseDPtr( theDialog ))->SetDialogKind( theKind );
}
void NemesisShowDialog( DialogRef &theDialog )
{
SelectWindow( theDialog );
NemesisUpdateMenus( FrontWindow() );
ShowWindow( theDialog );
}
short NemesisIsDialog( WindowRef theWindow )
{
Boolean result = kNotDialog;
short windowVariant;
if ( theWindow )
{
if ( GetWindowKind( theWindow ) == dialogKind ) // This may change when Copland comes
{
windowVariant = GetWVariant( theWindow );
switch ( windowVariant )
{
case dBoxProc:
case plainDBox:
case altDBoxProc:
result = kModal;
break;
case noGrowDocProc:
result = kModeless;
break;
case movableDBoxProc:
result = kMovableModal;
break;
}
}
}
return(result);
}